package cre.simple.jpa.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cre.simple.jpa.dao.UserDao;
import cre.simple.jpa.domain.AccountInfo;
import cre.simple.jpa.domain.UserInfo;

/**
 * 
 * @author Cre.Gu
 *
 */
@Service("userService")
public class UserServiceImpl implements UserService {
	@Autowired
	private UserDao userDao;

	@Transactional
	public AccountInfo createNewAccount(String username, String password, Integer init) {
		// 封装域对象
		AccountInfo accountInfo = new AccountInfo();
		UserInfo userInfo = new UserInfo();

		userInfo.setUsername(username);
		userInfo.setPassword(password);

		accountInfo.setBalance(init);
		accountInfo.setUserInfo(userInfo);

		// 调用持久层，完成数据的保存
		return userDao.save(accountInfo);
	}
}
